package model;

import java.time.LocalDate;

public abstract class Resource {
    private final String id;
    private final String title;
    private boolean isBorrowed;
    private LocalDate dueDate;
    private String borrowerId;

    public Resource(String id, String title) {
        this.id = id;
        this.title = title;
        this.isBorrowed = false;
    }

    // 抽象方法 - 由子类实现具体细节
    public abstract String getDetails();

    // 借出资源
    public boolean borrow(String borrowerId, int loanPeriodDays) {
        if (isBorrowed) return false;

        this.isBorrowed = true;
        this.borrowerId = borrowerId;
        this.dueDate = LocalDate.now().plusDays(loanPeriodDays);
        return true;
    }

    // 归还资源
    public void returnResource() {
        this.isBorrowed = false;
        this.borrowerId = null;
        this.dueDate = null;
    }

    // 检查是否可用Getters
    public boolean isAvailable() {
        return !isBorrowed;
    }

    //
    public String getId() { return id; }
    public String getTitle() { return title; }
    public boolean isBorrowed() { return isBorrowed; }
    public LocalDate getDueDate() { return dueDate; }
    public String getBorrowerId() { return borrowerId; }

    public abstract boolean borrow(String borrowerId);
}